main.controller('mloginCtrl', ["$scope", "$rootScope", "$location", "tools", "$http", 'userConfig', function ($scope, $rootScope, $location, tools, $http, userConfig) {
    $('.ui.checkbox').checkbox({
        checked: 'checked'
    });

    $scope.rememberPwd = !!window.localStorage.getItem('pwd');

    $scope.user = {
        userName: window.localStorage.getItem('userName') || '',
        pwd: window.localStorage.getItem('pwd'),
        password: ''
    };

    $scope.errInfo = "";

    $scope.login = function () {
        $scope.user.userName = tools.trim($scope.user.userName);
        $scope.user.pwd = tools.trim($scope.user.pwd);

        if ($scope.user.userName === '') {
            return $scope.errInfo = "用户名不能为空!";
        } else if ($scope.user.pwd === '') {
            return $scope.errInfo = "密码不能为空!";
        }

        $scope.user.password = hex_md5($scope.user.pwd);
        $location.url('/accountManager');

        // $scope.user.pwd = hex_md5($scope.user.pwd);

        tools.get({
            url: '/Ibm-Client/',
            data: $scope.user,
            succ: function (resp) {
                if (resp.success) {
                    // 记住用户名
                    window.localStorage.setItem('userName', $scope.user.userName);
                    $location.url('/accountManager');
                } else {
                    $scope.errInfo = '用户名或者密码错误!';
                }
            }
        });
    }
    $scope.clear = function () {
        $scope.user.userName = $scope.user.pwd = $scope.errInfo = "";
    }
}]);